home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / SmallEiffel 0.3.3 / SmallEiffel PPC / lib_show / parking / parking.e < prev    next >
Encoding:
Text File  |  1996-06-13  |  2.5 KB  |  147 lines  |  [TEXT/EDIT]

  1. -- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C) 
  2. -- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
  3. --
  4. class PARKING
  5.  
  6. creation {ANY}
  7.    make
  8.  
  9. feature {ANY}
  10.    
  11.    lower_level: INTEGER is
  12.       do
  13.      Result := level_list.lower;
  14.       end;
  15.    
  16.    upper_level: INTEGER is
  17.       do
  18.      Result := level_list.upper;
  19.       end;
  20.    
  21.    hour_price: REAL;
  22.    
  23.    default_hour_price: REAL is 1.50;
  24.    
  25.    count: INTEGER is
  26.       local
  27.      i: INTEGER;
  28.       do
  29.      from  
  30.         i := lower_level;
  31.      until
  32.         i > upper_level
  33.      loop
  34.         Result := Result + level_count(i);
  35.         i := i + 1;
  36.      end;
  37.       end;
  38.    
  39.    clock: DATE;
  40.    
  41.    level_count(number: INTEGER): INTEGER is
  42.       require
  43.      number <= upper_level;
  44.      lower_level <= number;
  45.       do
  46.      Result := (level_list @ number).count;
  47.       ensure
  48.      Result >= 0;
  49.       end;
  50.  
  51. feature {ANY} -- Modifications :
  52.    
  53.    make(ll: like level_list) is
  54.       require
  55.      ll /= Void
  56.       do
  57.      !!clock.make(0,360);
  58.      hour_price := default_hour_price;
  59.      level_list := ll;
  60.      last_car := 0;
  61.       ensure
  62.      hour_price = default_hour_price;
  63.      level_list = ll;
  64.      last_car = 0;
  65.       end;
  66.    
  67.    arrival: INTEGER is
  68.       -- Gives 0 when no more place.
  69.       local
  70.      i: INTEGER;
  71.       do
  72.      from  
  73.         i := lower_level;
  74.      until
  75.         (i > upper_level) or else        
  76.         (not (level_list @ i).full)
  77.      loop
  78.         i := i + 1;
  79.      end;
  80.      if (i > upper_level) or else 
  81.         (level_list @ i).full  
  82.      then
  83.         Result := 0;
  84.      else
  85.         last_car := last_car + 1;
  86.         level_list.item(i).arrival(last_car,clone(clock));
  87.         Result := last_car;
  88.      end;
  89.       ensure
  90.      Result >= 0;
  91.       end;
  92.    
  93.    departure(car: INTEGER): REAL is
  94.      -- Gives the price to pay or -1 when car has already leaved. 
  95.       require
  96.      car > 0;
  97.       local
  98.      i: INTEGER;
  99.      stop: BOOLEAN;
  100.      c: like clock;
  101.       do
  102.      from  
  103.         i := lower_level;
  104.         stop := level_list.count <= 0;
  105.         Result := -1;
  106.         c := clone(clock);
  107.      until
  108.         stop
  109.      loop
  110.         Result := (level_list @ i).departure(car,c,hour_price);
  111.         i := i + 1;
  112.         stop := (Result >= 0) or (i > upper_level);
  113.      end;
  114.       end;
  115.    
  116.    add_time(incr: INTEGER) is
  117.       do
  118.      clock.add_time(incr);
  119.       end;
  120.    
  121.    set_hour_price(hp: REAL) is
  122.       require
  123.      hp >= 0;
  124.       do
  125.      hour_price := hp;
  126.       ensure
  127.      hour_price = hp;
  128.       end;
  129.  
  130. feature {NONE}
  131.    
  132.    level_list: ARRAY[LEVEL];
  133.    
  134.    last_car: INTEGER;
  135.  
  136. invariant
  137.    
  138.    valid_price: hour_price >= 0;
  139.      
  140.    clock /= Void;
  141.    
  142.    last_car >= 0;
  143.    
  144.    level_list /= Void;
  145.    
  146. end -- class PARKING
  147.